package com.xidian.zhiancloud.controller.helpCenter;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.CommonProblem;
import com.xidian.zhiancloud.qo.helpCenter.CommonProblemQO;
import com.xidian.zhiancloud.service.helpCenter.CommonProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 帮助中心 常见问题接口
 */
@RestController
@RequestMapping("/CommonProblem")
public class CommonProblemController extends BaseController {

    @Autowired
    private CommonProblemService commonProblemService;

    /**
     * 根据id获取常见问题
     * @param id 常见问题的id
     * @return 常见问题对象
     */
    @GetMapping("/getById")
    public ResultDTO<CommonProblem> getById(@RequestParam("id") Long id){
        return ResultDTO.successOf(commonProblemService.getById(id), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 条件查询
     * @param commonProblemQO 查询条件
     * @return 返回查询列表
     */
    @GetMapping("/getListByQO")
    public ResultDTO<IPage<CommonProblem>> getListByQueryObject(CommonProblemQO commonProblemQO) {
        if(commonProblemQO.getCurrent() == null || commonProblemQO.getSize() ==null){
            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
        }
        commonProblemQO.setCompanyId(getSessionUserCompanyId());
        return ResultDTO.successOf(commonProblemService.getListByQO(commonProblemQO), GeneralResponseEnums.SUCCESS);
    }
}
